package cn.echogo.ipart.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import cn.echogo.ipart.R;

public class PhotosGalleryActivity2 extends Activity implements OnTouchListener, OnClickListener, OnLongClickListener {
	
	private static final String tag = "PhotosGalleryActivity";
	ImageView iv;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.photos_gallery);
		
		iv = (ImageView) findViewById(R.id.imageView1);
		iv.setOnTouchListener(this);
		iv.setOnClickListener(this);
		iv.setOnLongClickListener(this);		
	}
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		Log.d(tag, "onTouch(" + event.getX() + "," + event.getY() + ")" + "  " + getTouchName(event.getAction()));
		
		return false;
	}
	
	@Override
	public void onClick(View v) {
		Log.d(tag, "onClick()");
	}
	
	@Override
	public boolean onLongClick(View v) {
		Log.d(tag, "onLongClick()");
//		return false;
		return true;
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Log.d(tag, "onTouchEvent(" + event.getX() + "," + event.getY() + ")" + "  " + getTouchName(event.getAction()));
		return super.onTouchEvent(event);
	}
	
	private String getTouchName(int touchCode) {
		String name;
		switch (touchCode) {
		case MotionEvent.ACTION_DOWN:
			name = "down";
			break;
		case MotionEvent.ACTION_UP:
			name = "up";
			break;
		case MotionEvent.ACTION_MOVE:
			name = "move";
			break;
		case MotionEvent.ACTION_CANCEL:
			name = "cancel";
			break;
		case MotionEvent.ACTION_POINTER_DOWN:
		case 261:		//(266&ACTION_MASK==5)
		case 517:
		case 773:
			name = "pointerDown";
			break;
		case MotionEvent.ACTION_POINTER_UP:
		case 262:
		case 518:
		case 774:
			name = "pointerUp";
			break;
		default:
			name = "" + touchCode;
			break;
		}
		return name;
	}
	
}
